package ru.timofeyco.justfeelbetter.db;

import ru.timofeyco.justfeelbetter.R;
import ru.timofeyco.justfeelbetter.model.DrillType;
import android.app.Activity;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.graphics.Color;

public class DatabaseOpenHelper extends SQLiteOpenHelper {
	private Activity context;

	public DatabaseOpenHelper(Context context, String name,
			CursorFactory factory, int version) {
		super(context, name, factory, version);
		this.context = (Activity)context;
	}
	
	public DatabaseOpenHelper(Context context) {
		super(context, JustFeelBetterDatabase.DB_NAME, null, JustFeelBetterDatabase.DB_VERSION);
		this.context = (Activity)context;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(JustFeelBetterDatabase.CREATE_DRILL_TYPE_TABLE);
		db.execSQL(JustFeelBetterDatabase.CREATE_DRILL_TABLE);
		db.execSQL(JustFeelBetterDatabase.CREATE_DAY_RESULTS_TABLE);
		
		initializeDefaultState(db);
	}
	
	private void initializeDefaultState(SQLiteDatabase db) {
		
		DrillType drillType1 = new DrillType(context.getString(R.string.first_drilltype), 20, Color.BLUE);
        DrillType drillType2 = new DrillType(context.getString(R.string.second_drilltype), 30, Color.RED);
        DrillType drillType3 = new DrillType(context.getString(R.string.third_drilltype), 10, Color.GREEN);       
		JustFeelBetterDatabase.insertDrillType(drillType1, db);
		JustFeelBetterDatabase.insertDrillType(drillType2, db);
        JustFeelBetterDatabase.insertDrillType(drillType3, db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {	
	}

}
